
import 'package:sciolto/POJO/storable.dart';
import 'package:sciolto/util/setting.dart';

///
/// 歌单实体类
/// 具有以下属性：
///   歌单的唯一标识id
///   歌单的名称
///   歌单的图标路径
///   歌单的点击量
///   歌单图片的图标来源类型
///   歌单的简介
///
class SongList extends Storable{

  int _id;                          // 唯一标识id
  String _listName;                 // 歌单名
  String _imagePath;                // 图片路径
  int hits;                        // 点击量
  ImageResourceType _resourceType;  // 图片来源
  String _introduce;

  // ignore: unnecessary_getters_setters
  set listName(String value) {
    _listName = value;
  } // 简介

  SongList(
      this._listName,
      this._imagePath,
      this._resourceType,
      this._introduce
      ){
    this.hits = 0;
    this._id = -1;
  }

  SongList.fromMap(Map<String, dynamic> map){
    assert(
      map["list_name"] != null &&
      map["image_path"] != null &&
      map["hits"] != null &&
      map["resource_type"] != null &&
      map["introduce"] != null &&
      map["id"] != null
    );
    this._listName = map["list_name"];
    this._imagePath = map["image_path"];
    this.hits = map["hits"];
    this._resourceType = ImageResourceType.values[map["resource_type"]];
    this._introduce = map["introduce"];
    this._id = map["id"];
  }

  // ignore: unnecessary_getters_setters
  String get introduce => _introduce;

  ImageResourceType get resourceType => _resourceType;

  String get imagePath => _imagePath;

  // ignore: unnecessary_getters_setters
  String get listName => _listName;

  int get id => _id;

  @override
  Map<String,dynamic> toMap(){
    Map<String, dynamic> result = {};
    result["list_name"] = listName;
    result["image_path"] = imagePath;
    result["hits"] = hits;
    result["resource_type"] = resourceType.index;
    result["introduce"] = introduce;
    if(id != -1) result['id'] = id;
    return result;
  }

  @override
  String toString() {
    return 'SongList{'
        'listName: $_listName, '
        'imagePath: $_imagePath, '
        'hits: $hits, '
        'resourceType: $_resourceType, '
        'introduce: $_introduce, '
        'id: $_id '
        '}';
  }

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is SongList &&
          runtimeType == other.runtimeType &&
          _listName == other._listName &&
          _imagePath == other._imagePath &&
          hits == other.hits &&
          _resourceType == other._resourceType &&
          _introduce == other._introduce;

  @override
  int get hashCode =>
      _id.hashCode ^
      _listName.hashCode ^
      _imagePath.hashCode ^
      hits.hashCode ^
      _resourceType.hashCode ^
      _introduce.hashCode;

  // ignore: unnecessary_getters_setters
  set introduce(String value) {
    _introduce = value;
  }
}

